package com.tian.service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tian.mapper.IntroMapper;
import com.tian.pojo.Intro;
import com.tian.vo.PageResult;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

@Service
public class IntroServiceImpl implements IntroService{
    @Autowired
    private IntroMapper introMapper;

    @Override
    public PageResult getlist(PageResult pageResult) {
        IPage page=new Page(pageResult.getPageNum(),pageResult.getPageSize());
        QueryWrapper<Intro> queryWrapper = new QueryWrapper<>();
        queryWrapper.like(StringUtils.hasLength(pageResult.getQuery()),"name", pageResult.getQuery());
        page=introMapper.selectPage(page,queryWrapper);
        long total = page.getTotal();
        List records = page.getRecords();
        return pageResult.setRows(records).setTotal(total);
    }
}
